﻿<%@ WebHandler Language="C#" Class="BindDropDownHandler" %>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Business.Common;
using WF_Business;

public class BindDropDownHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var typecode = context.Request["typecode"];
        context.Response.ContentType = "text/plain";
        context.Response.Write(GetOptionStrJson(typecode));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    private string GetOptionStrJson(string typecode)
    {
        var list = new List<DataDictionary>();
        var dtTemp = GetDataTable(typecode);
        dtTemp.Rows.Cast<DataRow>().ToList().ForEach(row => list.Add(new DataDictionary
        {
            Text = row["text"].ToString(),
            Value = row["value"].ToString()
        }));
        var result = new DropDownInfo { DataDic = list };
        return result.T2Json();
    }


    private DataTable GetDataTable(string typecode)
    {
        var dtTemp = new DataTable();
        var strSql = string.Format(" select text,value,typename,typecode,num from tb_sjzd where typecode='{0}' order by num ", typecode);
        SysParams.OAConnection().RunSql(strSql, out dtTemp);
        return dtTemp;
    }
}